function BXMedialibAdmin(e){window.MLItems={};this.arCollections=window.MLCollections;this.arItemsCollList={};this.oConfig=e;this.sessid=this.oConfig.sessid;this.zIndex=1e3;this.arItems={};this.curColl=this.oConfig.curColl;this.arExt=this.oConfig.strExt.split(",")}BXMedialibAdmin.prototype={OnStart:function(){this.pCollCont=BX("ml_coll_cont");this.pBread=BX("ml_breadcrumbs");this.Types=this.oConfig.Types;this.curType="";this.requestTypes=[];this.imageTypeId=0;var e,t,i,l,o,s;for(e=0,t=this.Types.length;e<t;e++){l=[];i=this.Types[e].ext.split(",");for(o=0;o<i.length;o++){s=BX.util.trim(i[o]);if(s.length>0)l.push(s.toLowerCase())}this.Types[e].arExt=l;if(this.Types[e].system&&this.Types[e].code=="image"){this.imageTypeId=this.Types[e].id;this.requestTypes.push(0)}this.requestTypes.push(this.Types[e].id)}this.InitMultiaction();this.InitContextMenu();this.InitTypeSelector();this.Search=new BXMLSearch(this);this.BuildCollections();if(this.curColl>0){this.SelectCollection(this.curColl,true);this.OpenCollection(this.curColl)}var n=BX("bxml-subdialog-cont");Array.from(n.children).forEach(function(e){document.body.appendChild(e)})},BuildCollections:function(){this.oCollections={};this.arCollectionsTree=[];this.bNoCollections=true;var e=[],t,i=0,l,o=this.arCollections.length;for(l=0;l<o;l++){if(!this.BuildCollection(this.arCollections[l],l))e.push([this.arCollections[l],l])}while(e.length>0&&i<50){o=e.length;t=[];for(l=0;l<o;l++){if(!this.BuildCollection(e[l][0],e[l][1]))t.push(e[l])}e=t;i++}this.bRedrawCollections=true;if(this.bNoCollections)BX("ml_no_colection_notice").style.display="block"},BuildCollection:function(e,t){if(!e)return false;if(!this.CheckMLType(e.type))return true;if(this.bNoCollections){this.bNoCollections=false;BX("ml_no_colection_notice").style.display="none"}var i,l,o=this,s;e.parent=parseInt(e.parent);if(!e.parent){i=this.pCollCont;l=0;s=this.arCollectionsTree}else if(this.oCollections[e.parent]){i=this.oCollections[e.parent].pCollsCont;l=this.oCollections[e.parent].level+1;this.oCollections[e.parent].childCount++;if(this.oCollections[e.parent].childCount==1)this.oCollections[e.parent].icon.className="ml-col-icon-closed";s=this._ReqFindChildCol(this.arCollectionsTree,e.parent)}else return false;s.push({id:e.id,child:[]});if(i){var n="",a,r=BX.create("DIV",{props:{id:"ml_coll_title_"+e.id}}),d=r.appendChild(BX.create("IMG",{props:{src:"/bitrix/images/1.gif",className:"ml-col-icon ml-col-icon-closed"}})),c={length:0},h=r.appendChild(BX.create("INPUT",{props:{type:"checkbox",value:"c_"+e.id}})),p=r.appendChild(BX.create("IMG",{props:{src:"/bitrix/images/1.gif",className:"ml-col-menu",id:"mlccm_"+e.id}})),m=r.appendChild(BX.create("SPAN",{props:{title:bxspcharsback(e.desc||e.name)},text:e.name})),u=BX.create("DIV"),f=u.appendChild(BX.create("TABLE")),C=f.insertRow(-1).insertCell(-1),y=f.insertRow(-1).insertCell(-1),g=f.insertRow(-1).insertCell(-1);C.className="ml-coll-items-cont";y.className="ml-coll-cols-cont";g.className="ml-coll-cols-cell-x";for(a=0;a<10;a++)n+="<img src='/bitrix/images/1.gif' />";g.innerHTML=n;if(c.del=!this.UserCan(e,"del"))c.length++;if(c.edit=!this.UserCan(e,"edit"))c.length++;if(c.add_col=!this.UserCan(e,"new_col"))c.length++;if(c.add_item=!this.UserCan(e,"new_item"))c.length++;if(c.access=!this.UserCan(e,"access"))c.length++;if(c.length<5){p.onmouseover=function(){BX.addClass(this,"ml-col-menu-over")};p.onmouseout=function(){BX.removeClass(this,"ml-col-menu-over")};p.onclick=function(e){o.oColMenu.Show({pElement:this,arHideItems:c});return BX.PreventDefault(e)}}else{p.className="ml-col-menu ml-col-menu-dis"}h.onclick=function(e){var t=this.value.substr("c_".length);if(!this.checked){var i=o.GetCollection(t);if(i&&i.parent>0&&o.oCollections[i.parent])o.oCollections[i.parent].pCheck.checked=false}o.CheckAllCollChild(t,!!this.checked,true);if(!e)e=window.event;if(e.stopPropagation)e.stopPropagation();else e.cancelBubble=true};o._SetColTitleLevel(r,u,l);r.onclick=function(){o.OpenCollection(this.id.substr("ml_coll_title_".length),true)};d.onclick=function(e){o.OpenCollection(this.parentNode.id.substr("ml_coll_title_".length),false,true);return BX.PreventDefault(e||window.event)};i.appendChild(r);i.appendChild(u);this.oCollections[e.id]={ind:t,pTitle:r,pChildCont:u,pCollsCont:y,pItemsCont:C,icon:d,level:l,childCount:0,bOpened:false,pCheck:h};return true}},ReNewCollectionTree:function(){this.bRedrawCollections=true;this.arCollectionsTree=[];var e=[],t,i=0,l,o=this.arCollections.length;for(l=0;l<o;l++){if(!this.CheckMLType(this.arCollections[l].type))continue;if(!this.ReNewCol4Tree(this.arCollections[l]))e.push(this.arCollections[l])}while(e.length>0&&i<50){o=e.length;t=[];for(l=0;l<o;l++){if(!this.ReNewCol4Tree(e[l]))t.push(e[l])}e=t;i++}},ReNewCol4Tree:function(e){var t=parseInt(e.parent),i;if(!t)i=this.arCollectionsTree;else if(this.oCollections[t])i=this._ReqFindChildCol(this.arCollectionsTree,t);if(!i)return false;i.push({id:e.id,child:[]});return true},SelectCollection:function(e,t){var i=this.oCollections[e];if(!i||this.SelectedColId==e)return;this.DeSelectCollection(false);this.SelectedColId=e;BX.addClass(i.pTitle,"mlcollt-active");BX.addClass(i.pChildCont,"mlcollt-active-ch");var l=this.GetCollsCrumbs(e);this.BuildCrumbs(l);if(t){var o,s=l.length;for(o=1;o<s;o++){if(!this.oCollections[l[o].id].bOpened)this.OpenCollection(l[o].id)}}},DeSelectCollection:function(e){if(this.SelectedColId&&this.oCollections[this.SelectedColId]){BX.removeClass(this.oCollections[this.SelectedColId].pTitle,"mlcollt-active");BX.removeClass(this.oCollections[this.SelectedColId].pChildCont,"mlcollt-active-ch")}if(e!==false)while(this.pBread.childNodes.length>0)this.pBread.removeChild(this.pBread.firstChild)},UserCan:function(e,t){var i;if(typeof e!=="object"){if(e===0){i=this.oConfig.rootAccess}else{e=this.GetCollection(e);if(typeof e!=="object")return false;i=e.access}}else{i=e.access}return i&&i[t]==="1"},GetCollsCrumbs:function(e){var t=[],i;while(e){i=this.GetCollection(e);if(i){t.push(i);e=i.parent}else e=false}return t},BuildCrumbs:function(e){while(this.pBread.childNodes.length>0)this.pBread.removeChild(this.pBread.firstChild);var t=this,i,l,o=e.length;for(l=o-1;l>=0;l--){i=e[l];if(!i||typeof i!="object")continue;pCr=this.pBread.appendChild(BX.create("DIV",{props:{className:"ml-crumb",id:"ml_crumb_"+i.id,title:i.desc},text:i.name}));if(l>0){this.pBread.appendChild(BX.create("DIV",{props:{className:"ml-crumb-sep"}})).appendChild(document.createTextNode(" "));pCr.onclick=function(){t.SelectCollection(this.id.substr("ml_crumb_".length))}}else{pCr.style.cursor="default"}}return e},GetCollection:function(e){if(this.oCollections[e])return this.arCollections[this.oCollections[e].ind];var t,i=this.arCollections.length;for(t=0;t<i;t++)if(this.arCollections[t].id==e)return this.arCollections[t];return false},_ReqFindChildCol:function(e,t){var i,l=e.length,o=false;for(i=0;i<l;i++){if(e[i].id==t){o=e[i].child;break}else if(e[i].child.length>0){o=this._ReqFindChildCol(e[i].child,t);if(o)break}}return o},_ReqBuildCollSelect:function(e,t,i,l){if(!i)i=0;var o,s=t.length,n=e.options.length,a,r,d;if(l==true){var c=1;while(e.options[c])e.options[c]=null}for(o=0;o<s;o++){col=this.GetCollection(t[o].id);if(col){r="";for(a=0;a<i;a++)r+=" . ";r+=bxspcharsback(col.name);d=new Option(r,t[o].id);d.title=bxspcharsback(col.name);e.options.add(d);if(t[o].child.length>0)this._ReqBuildCollSelect(e,t[o].child,i+1)}}},OpenCollection:function(e,t,i){var l=this.oCollections[e];if(!l||typeof l!="object")return;if(!l.bOpened||!i){if(t)this.SelectCollection(e);l.icon.className="ml-col-icon ml-col-icon-opened";l.pChildCont.style.display="block";if(l.childCount>0)l.pCollsCont.style.display="block";this.ShowItems(e)}else{l.pChildCont.style.display="none";l.icon.className="ml-col-icon ml-col-icon-closed"}l.bOpened=!l.bOpened},DelCollection:function(e){if(e>0&&confirm(ML_MESS.DelCollectionConf)){var t=[];if(this.oCollections[e].childCount>0){var i=this.oCollections[e].pChildCont.getElementsByTagName("DIV"),l,o=i.length,s;for(l=0;l<o;l++){if(i[l].id.substr(0,14)=="ml_coll_title_"){s=parseInt(i[l].id.substr(14));if(s>0)t.push(s)}}}var n=this;this.Request({action:"del_collection",postData:{id:e,child_cols:t},handler:function(){if(window.bx_req_res)n.CSDelCollection(e,t)}})}},_IncreaseCollChild:function(e,t){var i=this.oCollections[e];if(i){if(t!==-1){i.childCount++;if(i.childCount>0)i.icon.className="ml-col-icon "+(i.bOpened?"ml-col-icon-opened":"ml-col-icon-closed")}else{i.childCount--;if(i.childCount<=0)i.icon.className="ml-col-icon"}}},_SetColTitleLevel:function(e,t,i){e.className="ml-coll-title mlcolllevel-"+(i>3?3:i);t.className="ml-coll-child-cont mlchlevel-"+(i>3?3:i);if(i>=3)e.childNodes[1].className="ml-smaller-title"},SaveCollection:function(){var e=this.EditCollDialog,t=this,i={name:encodeURIComponent(e.pName.value),desc:encodeURIComponent(e.pDesc.value),keywords:encodeURIComponent(e.pKeys.value),parent:e.pParent.value,type:e.typeId};if(e.pName.value==""){alert(ML_MESS.ColNameError);e.pName.focus();return false}if(!e.bNew)i.id=e.oCol.id;this.Request({action:"edit_collection",postData:i,handler:function(){if(window.bx_req_res!==false){t.CloseEditCollDialog();var l={id:window.bx_req_res.id,name:e.pName.value,desc:e.pDesc.value,date:"",keywords:e.pKeys.value,parent:i.parent,access:window.bx_req_res.access,type:e.typeId};if(e.bNew){if(t.bNoCollections)return t.Refresh({curColl:l.id});t.arCollections.push(l);t.BuildCollection(l,t.arCollections.length-1)}else{var o=t.oCollections[l.id].pTitle,s=t.oCollections[l.id].pChildCont,n=t.arCollections[t.oCollections[l.id].ind].parent,a=l.parent||0;if(t.arCollections[t.oCollections[l.id].ind].parent!=a){t._IncreaseCollChild(n,-1);t._IncreaseCollChild(a);var r=a==0?t.pCollCont:t.oCollections[a].pChildCont;r.appendChild(o);r.appendChild(s);var d=a==0?0:t.oCollections[a].level+1;t.oCollections[l.id].level=d;t._SetColTitleLevel(o,s,d)}t.arCollections[t.oCollections[l.id].ind]=l;o.childNodes[3].innerHTML=BX.util.htmlspecialchars(l.name);o.title=l.desc||l.name}t.ReNewCollectionTree();t.SelectCollection(l.id)}else{alert("error")}}})},OpenEditCollDialog:function(e){if(!e)e={};if(!this.EditCollDialog)this.CreateEditCollDialog();this.EditCollDialog.bNew=!e.id;var t=this.EditCollDialog,i=BX.GetWindowSize(),l=parseInt(i.scrollLeft+i.innerWidth/2-t.width/2),o=parseInt(i.scrollTop+i.innerHeight/2-t.height/2);if(this.bRedrawCollections){this._ReqBuildCollSelect(t.pParent,this.arCollectionsTree,0,true);this.bRedrawCollections=false}t.pWnd.style.display="block";this.EditCollDialog.bFocusKeywords=false;if(!t.bNew){var s=this.GetCollection(e.id);t.pName.value=bxspcharsback(s.name);t.pDesc.value=bxspcharsback(s.desc);t.pKeys.value=bxspcharsback(s.keywords);t.pParent.value=s.parent||0;this.EditCollDialog.oCol=s}else{t.pName.value="";t.pDesc.value="";t.pKeys.value="";if(!e.parentCol&&e.bGetSelCol&&this.SelectedColId&&this.oCollections[this.SelectedColId])e.parentCol=this.SelectedColId;if(e.parentCol>0&&this.UserCan(e.parentCol,"new_col"))t.pParent.value=e.parentCol;var s=this.GetCollection(e.parentCol);if(s&&s.keywords)t.pKeys.value=s.keywords}t.typeId=this.curType.id||"";jsFloatDiv.Show(this.EditCollDialog.pWnd,l,o);t.Overlay.Show();t.pName.onchange();t.pName.focus();BX.bind(document,"keypress",window.MlEdColOnKeypress)},CreateEditCollDialog:function(e){var t=this,i={width:360,height:230,pWnd:BX("mlsd_coll"),pTitle:BX("mlsd_coll_title"),pName:BX("mlsd_coll_name"),pDesc:BX("mlsd_coll_desc"),pKeys:BX("mlsd_coll_keywords"),pParent:BX("mlsd_coll_parent"),Overlay:new BXOverlay({id:"bxml_ed_col_overlay"})};i.pName.onkeydown=i.pName.onchange=function(){setTimeout(function(){var e=t.EditCollDialog,i=bxhtmlspecialchars(e.pName.value),l=e.bNew?ML_MESS.NewCollection:ML_MESS.Collection;e.pTitle.title=l+(i.length>0?": "+e.pName.value:"");e.pTitle.innerHTML=l+(i.length>0?": "+i:"")},20)};i.pKeys.onchange=i.pKeys.onblur=function(){t.EditCollDialog.bFocusKeywords=true};i.pParent.onchange=function(){if(!t.EditCollDialog.bNew&&this.value==t.EditCollDialog.oCol.parent)return true;if(t.EditCollDialog.bNew&&!t.UserCan(parseInt(this.value),"new_col")||!t.EditCollDialog.bNew&&!t.UserCan(parseInt(this.value),"edit")){t._SetFirstAvailableCol();return alert(ML_MESS.CollAccessDenied3)}if(t.EditCollDialog.oCol){var e=t._ReqFindChildCol(t.arCollectionsTree,t.EditCollDialog.oCol.id);if(!e||t._ReqFindChildCol(e,this.value)){alert(ML_MESS.ColLocEr2);this.value=t.EditCollDialog.oCol.parent||0;return true}}if(!t.EditCollDialog.bNew&&t.EditCollDialog.oCol.id==this.value){alert(ML_MESS.ColLocEr);this.value=t.EditCollDialog.oCol.parent||0}if(t.EditCollDialog.bNew&&!t.EditCollDialog.bFocusKeywords&&this.value>0){var l=t.GetCollection(this.value);if(l&&l.keywords)i.pKeys.value=l.keywords}};BX("mlsd_coll_save").onclick=function(){t.SaveCollection()};BX("mlsd_coll_cancel").onclick=function(){t.CloseEditCollDialog()};BX("mlsd_coll_close").onclick=function(){t.CloseEditCollDialog()};this.bRedrawCollections=true;window.MlEdColOnKeypress=function(e){if(!e)e=window.event;if(e&&e.keyCode==27)t.CloseEditCollDialog()};i.pWnd.style.width=i.width+"px";i.pWnd.style.height="auto";i.pWnd.style.minHeight="10px";this.EditCollDialog=i;i.Overlay.Create();BX.ZIndexManager.register(i.pWnd,{overlay:i.Overlay.pWnd})},CloseEditCollDialog:function(){this.EditCollDialog.pWnd.style.display="none";jsFloatDiv.Close(this.EditCollDialog.pWnd);this.EditCollDialog.Overlay.Hide();BX.unbind(document,"keypress",window.MlEdColOnKeypress)},_SetFirstAvailableCol:function(e){var t=this.EditCollDialog,e=t.bNew?"new_col":"edit",i,l,o,s=t.pParent.options.length;if(!t.bNew&&t.oCol.parent)t.pParent.value=t.oCol.parent;if(this.oConfig.rootAccess[e])t.pParent.value=0;else{for(o=0;o<s;o++){i=t.pParent.options[o].value;l=this.GetCollection(i);if(l&&l.access&&l.access[e]){t.pParent.value=i;return}}}},ShowItems:function(e){var t=this,i=this.GetCollection(e),l={edit:this.UserCan(i,"edit_item"),del:this.UserCan(i,"del_item")};if(typeof MLItems[e]=="object")return this.DisplayItems({Items:MLItems[e],id:e,Access:l});this.Request({action:"get_items",postData:{col_id:e},handler:function(){if(!window.MLItems[e])return false;t.DisplayItems({Items:MLItems[e],id:e,Access:l})}})},DisplayItems:function(e){var t=e.id,i=this.oCollections[t].pItemsCont;i.style.display="block";while(i.firstChild)i.removeChild(i.lastChild);this.arItems[t]={};if(e.Items&&e.Items.length){var l,o=e.Items.length,s=false;if(this.arLoadItems[t])s=true;for(l=0;l<o;l++)this.DisplayItem({Item:e.Items[l],pCont:i,bCheck:s,id:t,Access:e.Access})}},DisplayItem:function(e){var t=e.Item,i=this,l=this.oConfig.thumbWidth,o=this.oConfig.thumbHeight,s=BX.create("DIV",{props:{id:"ml_item_"+t.id,className:"ml-item-cont",title:bxspcharsback(t.name)},style:{width:l+15+"px",height:o+35+"px"}}),n=s.appendChild(BX.create("INPUT",{props:{type:"checkbox",className:"item-checkbox",value:e.id+"|"+t.id}})),a=s.appendChild(BX.create("IMG",{props:{src:t.thumb_path||"/bitrix/images/1.gif",className:"ml-item-thumb"}})),r=s.appendChild(BX.create("DIV",{props:{className:"ml-item-title"},style:{width:l+8+"px"}}));var d=t.thumb_path||t.path;if(t.type=="image"&&d)a.style.backgroundImage="url('"+d+"')";t.trueHeight=e.Item.height;if(!t.thumb_path||!t.width||!t.height){BX.addClass(a,"ml-item-no-thumb");t.height=100}if(t.width<l&&t.height<o){var c=Math.round((o-t.height)/2);if(c>0)a.style.marginTop=c+"px"}r.appendChild(document.createTextNode(bxspcharsback(t.name)));if(e.bCheck)n.checked=true;n.onclick=function(){if(!this.checked&&i.oCollections[e.id])i.oCollections[e.id].pCheck.checked=false;i.EnableMultiAction(this.checked||i.AskAllCheckBoxes())};var h=s.appendChild(BX.create("DIV",{props:{className:"ml-item-but-cont"}}));var p=h.appendChild(BX.create("IMG",{props:{src:"/bitrix/images/1.gif",className:"ml-item-view",title:ML_MESS.ViewItem}}));p.onclick=function(t){var l=this.parentNode.parentNode.id.substr("ml_item_".length);i.GetItemCollList(l,"OpenViewItDialog",{id:l,colId:e.id,Access:e.Access,bSearch:e.bSearch});return BX.PreventDefault(t)};s.ondblclick=function(t){var l=this.id.substr("ml_item_".length);i.GetItemCollList(l,"OpenViewItDialog",{id:l,colId:e.id,Access:e.Access,bSearch:e.bSearch});return BX.PreventDefault(t)};if(e.Access.edit||e.Access.del){if(e.Access.edit){var m=h.appendChild(BX.create("IMG",{props:{src:"/bitrix/images/1.gif",className:"ml-item-edit",title:ML_MESS.EditItem}}));m.onclick=function(t){var l=this.parentNode.parentNode.id.substr("ml_item_".length);i.GetItemCollList(l,"OpenEditItemDialog",{id:l,colId:e.id,bSearch:e.bSearch});return BX.PreventDefault(t||window.event)}}if(e.Access.del){var u=h.appendChild(BX.create("IMG",{props:{src:"/bitrix/images/1.gif",className:"ml-item-del",title:ML_MESS.DelItem}}));u.onclick=function(t){var l=this.parentNode.parentNode.id.substr("ml_item_".length);i.GetItemCollList(l,"DelItem",{id:l,colId:e.id,bSearch:e.bSearch});return BX.PreventDefault(t||window.event)}}else{n.disabled=true;n.checked=false}s.onmouseover=function(){BX.addClass(this,"ml-item-cont-over")};s.onmouseout=function(){BX.removeClass(this,"ml-item-cont-over")}}s.onclick=function(t){if(!t)t=window.event;var i=t.target||t.srcElement;if(i.nodeType==3)i=i.parentNode;if(i&&i.nodeName&&i.nodeName.toLowerCase()!="input"&&e.Access.del)n.checked=!n.checked;n.onclick()};if(!e.bSearch)this.arItems[e.id][t.id]={oItem:t,pWnd:s};e.pCont.appendChild(s)},OpenViewItDialog:function(e){if(!this.ViewItDialog)this.CreateViewItDialog(e);var t,i,l,o=this.ViewItDialog;if(e.bSearch){l=window.MLSearchResult.length;for(i=0;i<l;i++){if(window.MLSearchResult[i].id==e.id){t=window.MLSearchResult[i];break}}}else if(MLItems[e.colId]){l=MLItems[e.colId].length;for(i=0;i<l;i++){if(MLItems[e.colId][i].id==e.id){t=MLItems[e.colId][i];break}}}if(!t)return;o.oItem=t;o.colId=e.colId;o.pDel.style.display=e.Access.del?"inline":"none";o.pEdit.style.display=e.Access.edit?"inline":"none";o.pWnd.style.display="block";o.pWnd.style.visibility="hidden";o.bOpened=true;o.Overlay.Show();this.SetItemInfo(t)},CreateViewItDialog:function(e){var t=this,i={width:100,height:100,pWnd:BX("mlsd_view_item"),pItemCont:BX("mlsd_item_cont"),pInfoCont:BX("mlsd_info_cont"),pName:BX("mlvi_info_name"),pCols:BX("mlvi_info_colls"),pKeys:BX("mlvi_info_keys"),pDesc:BX("mlvi_info_desc"),pDetails:BX("mlvi_info_details"),pDel:BX("mlsd_viewit_del"),pEdit:BX("mlsd_viewit_edit"),pLink:BX("mlvi_info_link"),pCopyLink:BX("mlvi_info_copy_link"),pCopyInput:BX("mlvi_info_copy_input"),pExt:BX("mlvi_info_ext"),Overlay:new BXOverlay({id:"bxml_viewit_overlay"})};BX("mlsd_viewit_cancel").onclick=function(){t.CloseViewItDialog()};BX("mlsd_viewit_close").onclick=function(){t.CloseViewItDialog()};i.pDel.onclick=function(e){t.DelItem({id:t.ViewItDialog.oItem.id,colId:t.ViewItDialog.colId})};i.pEdit.onclick=function(i){t.CloseViewItDialog();t.OpenEditItemDialog({id:t.ViewItDialog.oItem.id,colId:t.ViewItDialog.colId,bSearch:e.bSearch})};window.MlViewItOnKeypress=function(e){if(!e)e=window.event;if(e&&e.keyCode==27)t.CloseViewItDialog()};this.ViewItDialog=i;i.Overlay.Create();BX.ZIndexManager.register(i.pWnd,{overlay:i.Overlay.pWnd})},CloseViewItDialog:function(){this.ViewItDialog.bOpened=false;this.ViewItDialog.pWnd.style.display="none";this.ViewItDialog.pCopyInput.style.display="none";if(typeof videojs!=="undefined"&&(player=BX.findChild(BX("mlsd_item_cont"),{class:"video-js"},false)))videojs(player.id).pause();if(player=BX.findChild(BX("mlsd_item_cont"),{tag:"div"},false)&&typeof jwplayer!=="undefined")jwplayer(player.id).stop();jsFloatDiv.Close(this.ViewItDialog.pWnd);this.ViewItDialog.Overlay.Hide();BX.unbind(document,"keypress",window.MlViewItOnKeypress)},SetItemInfo:function(e){var t=this,i=this.ViewItDialog,l=this.arItemsCollList[e.id],o="",s,n=l.length,a,r;i.pName.innerHTML=BX.util.htmlspecialchars(e.name);i.pName.title=e.name;i.pLink.onclick=function(){if(e.path_external&&(e.path.substr(0,1)!=="/"||e.path!==e.path_external)){var t=e.path_external}else{t="fileman_file_download.php?path="+BX.util.urlencode(e.path)}jsUtils.Redirect([],t)};i.pCopyLink.onclick=function(){if(e.path_external&&(e.path.substr(0,1)!=="/"||e.path!==e.path_external)){i.pCopyInput.value=e.path_external}else{i.pCopyInput.value=window.location.protocol+"//"+window.location.host+e.path}i.pCopyInput.style.display="block";i.pCopyInput.select()};if(e.keywords.length>0){i.pKeys.parentNode.className="small-grey";i.pKeys.innerHTML=BX.util.htmlspecialchars(e.keywords);i.pKeys.title=e.keywords}else{i.pKeys.parentNode.className="ml-info-keys-h"}if(e.desc.length>0){i.pDesc.innerHTML=BX.util.htmlspecialchars(e.desc.replace(/\n/g,"<br />"));i.pDesc.parentNode.className="small-grey"}else{i.pDesc.parentNode.className="ml-info-desc-h"}for(var d=i.pCols.childNodes.length-1;d>0;d--)if(i.pCols.childNodes[d].nodeName.toLowerCase()!="span")i.pCols.removeChild(i.pCols.childNodes[d]);for(s=0;s<n;s++)o+=BX.util.htmlspecialcharsback(this.GetCollection(l[s]).name+(s!=n-1?", ":""));i.pCols.appendChild(document.createTextNode(o));var c=ML_MESS.FileExt+": "+e.path.substr(e.path.lastIndexOf(".")+1);c+="<br />"+ML_MESS.DateModified+": "+e.date_mod;if(e.file_size)c+="<br />"+ML_MESS.FileSize+": "+e.file_size;if(e.width&&e.height)c+="<br />"+ML_MESS.ImageSize+": "+e.width+" x "+e.trueHeight+" px";i.pDetails.innerHTML=c;this.SetItemHTML(e)},SetItemHTML:function(e){var t=this.ViewItDialog,i=this;this.Request({action:"get_item_view",postData:{id:e.id},handler:function(){var e=window.bx_req_res.html;var i=[],l,o,s,n;while((l=e.indexOf("<"+"script>"))!=-1){var o=e.indexOf("</"+"script>",l);if(o==-1)break;i[i.length]=e.substr(l+8,o-l-8);e=e.substr(0,l)+e.substr(o+9)}for(var s=0,n=i.length;s<n;s++)if(i[s]!="")jsUtils.EvalGlobal(i[s]);t.pItemCont.innerHTML=e;var a=parseInt(window.bx_req_res.width)||100,r=parseInt(window.bx_req_res.height)||50;if(a<100)a=100;if(t.pDesc&&parseInt(t.pDesc.offsetHeight)>r-200){t.pDesc.style.height=(r>=400?r-200:200)+"px";t.pDesc.style.overflow="auto"}var d=parseInt(t.pInfoCont.offsetHeight)||0,c=80+(r>d?r:d),h=270+a,p=BX.GetWindowSize(),m=parseInt(p.scrollLeft+p.innerWidth/2-h/2),u=parseInt(p.scrollTop+p.innerHeight/2-c/2);t.pWnd.style.width=h+"px";t.pWnd.style.height=c+"px";t.pWnd.style.overflow="hidden";jsFloatDiv.Show(t.pWnd,m,u);BX.bind(document,"keypress",window.MlViewItOnKeypress);t.pItemCont.style.width=a+"px";t.pItemCont.style.height=r+"px";t.pWnd.style.visibility="visible"}})},DelItem:function(e){if(!e.id)return;var t=this,i=false,l=this.arItemsCollList[e.id],o,s=l.length,n;for(o=0;o<s;o++){if(!this.GetCollection(l[o])){i=true;break}}if(!e.mode&&e.bSearch)return this.OpenConfirm({text:ML_MESS.DelElConfirm,but1:{text:ML_MESS.DelElConfirmYes,handler:function(){t.DelItem({id:e.id,colId:e.colId,mode:"all",bSearch:true})},width:100},width:380,height:100});if(!e.mode)return this.OpenConfirm({text:ML_MESS.DelItConfTxt,but1:{text:ML_MESS.DelItB1,handler:function(){t.DelItem({id:e.id,colId:e.colId,mode:"current"})},width:180},but2:{text:ML_MESS.DelItB2,handler:function(){t.DelItem({id:e.id,colId:e.colId,mode:"all"})},disabled:i,width:160}});var a=e.colId||0;this.Request({action:"del_item",postData:{id:e.id,mode:e.mode,col_id:a},handler:function(){if(window.bx_req_res==true)t.CSDelItem({id:e.id,mode:e.mode,colId:a,bSearch:e.bSearch});else if(window.bx_req_res!==false)return false}})},_ChooseKeysCount:function(e,t,i,l,o){var s=this;e.innerHTML=i;setTimeout(function(){var n=parseInt(t.offsetHeight),a=i.lastIndexOf(",");if(n>l&&a>0)s._ChooseKeysCount(e,t,BX.util.trim(i.substr(0,a)),l,true);else if(o)e.innerHTML+="..."},1)},GetItemCollList:function(e,t,i){if(!this.arItemsCollList[e]){var l=this;this.Request({action:"get_item_coll_list",postData:{id:e},handler:function(){if(!window._ml_items_colls)return false;l.arItemsCollList[e]=[];for(var o=0,s=window._ml_items_colls.length;o<s;o++)l.arItemsCollList[e].push(window._ml_items_colls[o]);l[t](i)}})}else this[t](i)},OpenEditItemDialog:function(e,t){if(!this.EditItemDialog)return this.CreateEditItemDialog(e);else if(!t){this.Request({action:"bx_test",handler:function(){}});this.EditItemDialog.alreadySubmitted=false;this.EditItemDialog.alreadyLoaded=false;this.EditItemDialog.Params=e||this.EditItemDialog.Params||{};this.EditItemDialog.pIfrm.src=this.GetRequestUrl("upload_form");return}var i=this,l=this.EditItemDialog,o=l.Params.id,s=BX.GetWindowSize(),n=parseInt(s.scrollLeft+s.innerWidth/2-l.width/2),a=parseInt(s.scrollTop+s.innerHeight/2-l.height/2);l.bNew=!o;l.Overlay.Show();l.pWnd.style.display="block";this.EditItemDialog.bShow=true;l.arColls={};l.colLength=0;if(!l.bNew){if(l.Params.bSearch){var r,d;d=window.MLSearchResult.length;for(r=0;r<d;r++){if(window.MLSearchResult[r].id==o){c=window.MLSearchResult[r];break}}}else{var c=this.arItems[l.Params.colId][o].oItem}l.pPCFileCont.style.display=l.pLoadFDLink.style.display=l.pFDFileCont.style.display=l.pLoadPCLink.style.display="none";l.pFNFileCont.style.display="block";l.pChangeFileLink.style.display="inline";l.pChangeFileLinkBack.style.display="none";l.pFileName.innerHTML=c.file_name;this._AddItemsCollections(this.arItemsCollList[o]);l.pName.value=bxspcharsback(c.name);l.pDesc.value=bxspcharsback(c.desc);l.pKeys.value=bxspcharsback(c.keywords);if(c.width&&c.height){l.pSize.style.display="block";l.pSize.innerHTML=c.width+" x "+c.trueHeight}else{l.pSize.style.display="none"}if(c.thumb_path){l.pThumb.src=c.thumb_path;l.pNoPreview.style.display="none";if(c.width>146||c.height>136){if(c.width-c.height>0)l.pThumb.style.width="146px";else l.pThumb.style.height="136px"}else if(c.height<126){l.pThumb.style.marginTop=Math.round((126-c.height)/2)+"px"}}l.oItem=c}else{l.pFNFileCont.style.display="none";l.pChangeFileLink.style.display="none";l.pChangeFileLinkBack.style.display="none";l.pFileName.innerHTML="";l.pName.value="";l.pDesc.value="";l.pKeys.value="";l.pSize.style.display="none";if(!l.Params.parentCol&&l.Params.bGetSelCol&&this.SelectedColId&&this.oCollections[this.SelectedColId])l.Params.parentCol=this.SelectedColId;if(l.Params.parentCol>0&&this.UserCan(l.Params.parentCol,"new_item"))this._AddItemsCollections([l.Params.parentCol])}this._ReHeightEditDialog();l.pName.onchange();jsFloatDiv.Show(l.pWnd,n,a);window.MlEdItemOnKeypress=function(e){if(!e)e=window.event;if(e&&e.keyCode==27)i.CloseEditItemDialog()};BX.bind(document,"keypress",window.MlEdItemOnKeypress)},CreateEditItemDialog:function(e){var t=this,i={Params:e||false,width:420,height:350,pWnd:BX("mlsd_item"),pTitle:BX("mlsd_item_title"),pIfrm:BX("mlsd_iframe_upload"),Overlay:new BXOverlay({id:"bxml_ed_it_overlay"})};i.pIfrm.src=this.GetRequestUrl("upload_form");var t=this;if(BX.browser.IsIE())i.pIfrm.onreadystatechange=function(){t.EditItemDialogOnload()};else i.pIfrm.onload=function(){t.EditItemDialogOnload()};BX("mlsd_item_cancel").onclick=BX("mlsd_item_close").onclick=function(){t.CloseEditItemDialog()};i.pWnd.style.width=i.width+"px";i.pWnd.style.height=i.height+"px";this.EditItemDialog=i;i.Overlay.Create();BX.ZIndexManager.register(i.pWnd,{overlay:i.Overlay.pWnd})},EditItemDialogOnload:function(){var e=this,t=this.EditItemDialog;t.pFrameDoc=t.pIfrm.contentDocument||t.pIfrm.contentWindow.document;t.pName=t.pFrameDoc.getElementById("mlsd_item_name");t.bFocusKeywords=false;if(!t.pName&&!this.EditItemDialog.alreadyLoaded)return;if(!t.pName&&this.EditItemDialog.alreadyLoaded&&!this.EditItemDialog.alreadySubmitted){this.EditItemDialog.alreadySubmitted=true;return setTimeout(function(){e.CSEditItem(top.bx_req_res,top._ml_items_colls)},50)}if(this.EditItemDialog.alreadyLoaded||this.EditItemDialog.alreadySubmitted)return;this.EditItemDialog.alreadyLoaded=true;t.pDesc=t.pFrameDoc.getElementById("mlsd_item_desc");t.pKeys=t.pFrameDoc.getElementById("mlsd_item_keywords");t.pColSelect=t.pFrameDoc.getElementById("mlsd_coll_sel");t.pItCollCont=t.pColSelect.parentNode.parentNode;t.pFNFileCont=t.pFrameDoc.getElementById("mlsd_fname_cont");t.pPCFileCont=t.pFrameDoc.getElementById("mlsd_load_cont");t.pFDFileCont=t.pFrameDoc.getElementById("mlsd_select_cont");t.pLoadFile=t.pFrameDoc.getElementById("ml_load_file");t.pLoadMaxSize=t.pFrameDoc.getElementById("ml_load_max_size");t.pChangeFileLink=t.pFrameDoc.getElementById("mlsd_fname_change");t.pChangeFileLinkBack=t.pFrameDoc.getElementById("mlsd_fname_change_back");t.pLoadPCLink=t.pFrameDoc.getElementById("mlsd_select_pc");t.pLoadFDLink=t.pFrameDoc.getElementById("mlsd_select_fd");t.pItemColls=t.pFrameDoc.getElementById("mlsd_item_collections");t.pFileName=t.pFrameDoc.getElementById("ml_file_name");t.pId=t.pFrameDoc.getElementById("mlsd_item_id");t.pNoPreview=t.pFrameDoc.getElementById("mlsd_no_preview");t.pFileName=t.pFrameDoc.getElementById("ml_file_name");t.pThumb=t.pFrameDoc.getElementById("mlsd_item_thumb");t.pSize=t.pFrameDoc.getElementById("mlsd_item_size");t.pItemPath=t.pFrameDoc.getElementById("mlsd_item_path");t.pOpenFD=t.pFrameDoc.getElementById("mlsd_open_fd");t.pSourceType=t.pFrameDoc.getElementById("mlsd_source_type");t.pSaveBut=BX("mlsd_item_save");t.pForm=t.pFrameDoc.forms["ml_item_form"];t.pTbl=t.pForm.firstChild;t.pItemPath.onchange=t.pLoadFile.onchange=function(){var e=this.value;if(!e||e.length<=0)return;e=e.replace(/\\/g,"/");e=e.substr(e.lastIndexOf("/")+1);t.pName.value=e;t.pName.onchange()};t.pName.onkeydown=t.pName.onchange=function(){setTimeout(function(){var t=e.EditItemDialog,i=bxhtmlspecialchars(t.pName.value),l=t.bNew?ML_MESS.NewItem:ML_MESS.Item;t.pTitle.title=l+(i.length>0?": "+t.pName.value:"");t.pTitle.innerHTML=l+(i.length>0?": "+i:"")},20)};t.pLoadFDLink.onclick=function(){t.pPCFileCont.style.display=t.pLoadFDLink.style.display="none";t.pFDFileCont.style.display="block";t.pLoadPCLink.style.display="inline";t.pSourceType.value="FD"};t.pLoadPCLink.onclick=function(){t.pPCFileCont.style.display="block";t.pLoadFDLink.style.display="inline";t.pFDFileCont.style.display=t.pLoadPCLink.style.display="none";t.pSourceType.value="PC"};t.pChangeFileLink.onclick=function(){t.pFNFileCont.style.display="none";t.pChangeFileLink.style.display="none";t.pChangeFileLinkBack.style.display="inline";t.pLoadPCLink.onclick()};t.pChangeFileLinkBack.onclick=function(){t.pPCFileCont.style.display=t.pLoadFDLink.style.display=t.pFDFileCont.style.display=t.pLoadPCLink.style.display="none";t.pFNFileCont.style.display="block";t.pChangeFileLink.style.display="inline";t.pChangeFileLinkBack.style.display="none";t.pSourceType.value="N"};t.pColSelect.onchange=function(){e._AddCollToItem(this.value);this.value=0};t.pSaveBut.onclick=function(){if(e.EditItemDialogOnsubmit()){t.pForm.submit();e.CloseEditItemDialog()}};t.pOpenFD.onclick=window.mlOpenFileDialog;window.mlOnFileDialogSave=function(e,i,l){var o=(i=="/"?"":i)+"/"+e;t.pItemPath.value=o;t.pItemPath.focus();t.pItemPath.select()};t.pKeys.onchange=t.pKeys.onblur=function(){e.EditItemDialog.bFocusKeywords=true};this._ReqBuildCollSelect(t.pColSelect,this.arCollectionsTree,0,true);this.OpenEditItemDialog(false,true)},EditItemDialogOnsubmit:function(){var e=this.EditItemDialog,t,i=this.EditItemDialog.arColls,l="";for(t in i)if(i[t]&&typeof i[t]=="object"&&i[t].pWnd)l+=(l==""?"":",")+t;var o=e.pSourceType.value=="PC"?e.pLoadFile.value:e.pItemPath.value;if((e.bNew||o!=="")&&!this.CheckFileExt(o)){alert(ML_MESS.ItemExtError);return}if((e.bNew||o!=="")&&!this.CheckFileExt(o,this.curType.arExt)&&!confirm(ML_MESS.CheckExtTypeConf))return false;if(e.bNew){var s=true;if(o=="")alert(ML_MESS.ItSourceError);else s=false;if(s){if(e.pSourceType.value=="PC"){e.pLoadPCLink.onclick();e.pLoadFile.focus()}else{e.pLoadFDLink.onclick();e.pItemPath.focus()}return false}}if(e.pName.value==""){alert(ML_MESS.ItNameError);e.pName.focus();return false}if(l==""){alert(ML_MESS.ItCollsError);e.pColSelect.focus();return false}if(!this.EditItemDialog.bNew)this.EditItemDialog.pId.value=this.EditItemDialog.oItem.id;this.EditItemDialog.pItemColls.value=l;return true},CloseEditItemDialog:function(){this.EditItemDialog.bShow=false;this.EditItemDialog.Params=false;this.EditItemDialog.pWnd.style.display="none";jsFloatDiv.Close(this.EditItemDialog.pWnd);this.EditItemDialog.Overlay.Hide();BX.unbind(document,"keypress",window.MlEdItemOnKeypress)},_AddItemsCollections:function(e){var t,i=e.length;for(t=0;t<i;t++)this._AddCollToItem(e[t],false)},_AddCollToItem:function(e,t){if(this.EditItemDialog.arColls[e])return;if(this.EditItemDialog.bNew&&!this.UserCan(parseInt(e),"new_item")||!this.EditItemDialog.bNew&&!this.UserCan(parseInt(e),"edit_item"))return alert(ML_MESS.CollAccessDenied4);var i=this.GetCollection(e);if(!i)return;var l,o,s=this,n=this.EditItemDialog.pColSelect,a=BX.create("DIV",{props:{className:"mlsd-ch-col",title:i.name}},this.EditItemDialog.pFrameDoc),r=a.appendChild(BX.create("SPAN",{text:i.name},this.EditItemDialog.pFrameDoc)),d=a.appendChild(BX.create("IMG",{props:{src:"/bitrix/images/1.gif",className:"ml-col-del",title:ML_MESS.DelColFromItem,id:"mlsd_it_"+e}},this.EditItemDialog.pFrameDoc));if(i.keywords&&this.EditItemDialog.bNew&&!this.EditItemDialog.bFocusKeywords)this.AppendKeywords(this.EditItemDialog.pKeys,i.keywords);this.EditItemDialog.pItCollCont.onmouseover=function(e){};this.EditItemDialog.pItCollCont.onmouseout=function(e){};a.onmouseover=function(e){BX.addClass(this,"col-over")};a.onmouseout=function(e){parent.BX.removeClass(this,"col-over")};d.onclick=function(e){var t=this.id.substr("mlsd_it_".length);s.EditItemDialog.pItCollCont.removeChild(s.EditItemDialog.arColls[t].pWnd);s._SelectOptionInColList(s.EditItemDialog.pColSelect,t,false);s.EditItemDialog.arColls[t]=null;s.EditItemDialog.colLength--;s._ReHeightEditDialog()};this.EditItemDialog.colLength++;this.EditItemDialog.pItCollCont.insertBefore(a,n.parentNode);s._SelectOptionInColList(n,e);if(t!==false)this._ReHeightEditDialog();this.EditItemDialog.arColls[e]={pWnd:a}},_SelectOptionInColList:function(e,t,i){for(var l=0,o=e.options.length;l<o;l++){if(e.options[l].value==t){e.options[l].className=i!==false?"opt-checked":"";e.options[l].title=i!==false?ML_MESS.CheckedColTitle:"";break}}},_ReHeightEditDialog:function(){var e=Math.ceil((this.EditItemDialog.colLength+2)/4);if(e<2)e=2;var t=(e-2)*28;this.EditItemDialog.pItCollCont.style.height=e*28+"px";this.EditItemDialog.pIfrm.style.height=275+t+"px";this.EditItemDialog.pTbl.style.height=265+t+"px";this.EditItemDialog.pWnd.style.height=350+t+"px";jsFloatDiv.AdjustShadow(this.EditItemDialog.pWnd)},GetRequestUrl:function(e,t){return"/bitrix/admin/fileman_medialib.php?sessid="+(t||this.sessid)+"&lang="+this.oConfig.lang+(e?"&action="+e:"")},CheckReqLostSessid:function(e){var t="BX_ML_DUBLICATE_ACTION_REQUEST",i=e.indexOf(t);if(i==-1)return true;this.sessid=e.substring(i+t.length,e.lastIndexOf("--\x3e"));return this.sessid},Request:function(e){this.ShowWaitWindow();var t=this,i=0,l=new JCHttpRequest;l.Action=function(l){var o=function(){t.CloseWaitWindow();if(l.indexOf("BX_ML_LOAD_OK")==-1)return alert(ML_MESS.AccessDenied);var s=t.CheckReqLostSessid(l);if(s!==true){if(e.bRequestReply)alert(ML_MESS.SessExpired);else{e.bRequestReply=true;setTimeout(function(){t.Request(e)},50)}return}var n=e.handler(l);if(n===false&&++i<20)setTimeout(o,3)};setTimeout(o,10)};window.bx_req_res=false;l.Post(this.GetRequestUrl(e.action),e.postData?ConvertArray2Post(e.postData):"")},ShowWaitWindow:function(){if(window.ShowWaitWindow)ShowWaitWindow()},CloseWaitWindow:function(){if(window.CloseWaitWindow)CloseWaitWindow()},OpenConfirm:function(e){var t=e.width||560,i=e.height||100,l=700,o=this;if(!this.Confirm){var s={pWnd:BX("ml_colfirm_dialog"),pText:BX("ml_confd_text"),but1:BX("ml_confd_b1"),but2:BX("ml_confd_b2"),butCancel:BX("ml_confd_cancel"),Overlay:new BXOverlay({id:"bxml_conf_overlay",parCont:BX("ml_colfirm_dialog").parentNode})};s.butCancel.onclick=function(){o.CloseConfirm()};s.Overlay.Create();BX.ZIndexManager.register(s.pWnd,{overlay:s.Overlay.pWnd})}else{var s=this.Confirm}s.pWnd.style.width=t+"px";s.pWnd.style.height=i+"px";s.pWnd.style.display="block";var n=BX.GetWindowSize(),a=parseInt(n.scrollLeft+n.innerWidth/2-t/2),r=parseInt(n.scrollTop+n.innerHeight/2-i/2);jsFloatDiv.Show(s.pWnd,a,r,0);s.Overlay.Show({clickCallback:{func:this.CloseConfirm,obj:this}});s.but1.value=e.but1.text;s.but1.onclick=function(t){e.but1.handler(t);o.CloseConfirm()};s.but1.disabled=!!e.but1.disabled;if(e.but1.width&&!isNaN(parseInt(e.but1.width)))s.but1.style.width=parseInt(e.but1.width)+"px";s.but1.focus();if(e.but2){s.but2.style.display="inline";s.but2.value=e.but2.text;s.but2.disabled=!!e.but2.disabled;s.but2.onclick=function(t){e.but2.handler(t);o.CloseConfirm()};if(e.but2.width&&!isNaN(parseInt(e.but2.width)))s.but2.style.width=parseInt(e.but2.width)+"px"}else{s.but2.style.display="none"}s.pText.innerHTML=e.text;this.Confirm=s;window.MlConfDialofOnKeypress=function(e){if(!e)e=window.event;if(e&&e.keyCode==27)o.CloseConfirm()};BX.bind(document,"keypress",window.MlConfDialofOnKeypress)},CloseConfirm:function(){this.Confirm.pWnd.style.display="none";jsFloatDiv.Close(this.Confirm.pWnd);this.Confirm.Overlay.Hide();BX.unbind(document,"keypress",window.MlConfDialofOnKeypress)},SaveSettings:function(){if(this.width&&this.height){this.userSettings.width=this.width;this.userSettings.height=this.height}this.Request({action:"save_settings",postData:this.userSettings,handler:function(){}})},CSDelCollection:function(e,t){var i=this.oCollections[e];if(i){var l=this.GetCollection(e);if(t!==false&&typeof l=="object"&&l.parent>0)this._IncreaseCollChild(parseInt(l.parent),-1);if(this.SelectedColId&&this.SelectedColId==e)this.DeSelectCollection();this.arCollections=BX.util.deleteFromArray(this.arCollections,i.ind);var o=i.pChildCont.parentNode;if(o){o.removeChild(i.pChildCont);o.removeChild(i.pTitle)}var s=true;for(var n=0,a=o.childNodes.length;n<a;n++){if(o.childNodes[n]&&o.childNodes[n].nodeName&&o.childNodes[n].nodeName.toUpperCase()=="DIV"){s=false;break}}if(s)return this.Refresh();this.oCollections[e]=null;if(t){for(var n=0,a=t.length;n<a;n++)this.CSDelCollection(t[n],false)}if(t!==false)this.ReNewCollectionTree()}},CSDelItem:function(e){var t=e.id,i=[];if(e.colId=="search_result")e.bSearch=true;if(e.bSearch){var l,o=window.MLSearchResult.length;for(l=0;l<o;l++){if(window.MLSearchResult[l].id==t){n=window.MLSearchResult[l];break}}}else{var s=parseInt(e.colId),n=this.arItems[s][parseInt(t)]}if(!n)return;if(this.ViewItDialog&&this.ViewItDialog.bOpened)this.CloseViewItDialog();if(e.mode=="current"){i.push(s);this.arItemsCollList[t]=false}else{if(!this.arItemsCollList[t])return this.GetItemCollList(t,"CSDelItem",e);i=this.arItemsCollList[t]}var l,o=i.length,a,r,d,c;for(l=0;l<o;l++){if(MLItems[i[l]]){a=MLItems[i[l]].length;for(r=0;r<a;r++){d=MLItems[i[l]][r];if(d.id==t){MLItems[i[l]]=BX.util.deleteFromArray(MLItems[i[l]],r);break}}this.ShowItems(i[l])}}if(this.Search.bShowed){var h,p=window.MLSearchResult.length,m;for(h=0;h<p;h++){m=window.MLSearchResult[h];if(m.id==t){window.MLSearchResult=BX.util.deleteFromArray(window.MLSearchResult,h);this.Search.DisplayResult(window.MLSearchResult,this.Search.Query);break}}}},CSEditItem:function(e,t){if(!e){if(parseInt(this.EditItemDialog.pLoadFile.files[0].size)>parseInt(this.EditItemDialog.pLoadMaxSize.value)){var i=parseInt(this.EditItemDialog.pLoadMaxSize.value)/(1024*1024);return alert(ML_MESS.ItFileSizeError.replace("#FILESIZE#",i))}}if(!e||typeof t!="object")return alert(ML_MESS.EditItemError);var l,o=t.length,s=e.id,n,a=this.arItemsCollList[s]||[],r=a.length,d={};if(a.length>0){n=this.FindItem(a[0],s);if(n!==false)e=this._MergeItemInfo(MLItems[a[0]][n],e)}for(l=0;l<o;l++){if(MLItems[t[l]]){n=this.FindItem(t[l],s);if(n===false)MLItems[t[l]].push(e);else MLItems[t[l]][n]=e;d[t[l]]=true}}for(l=0;l<r;l++){if(!d[a[l]]){n=this.FindItem(a[l],s);if(n!==false){MLItems[a[l]]=BX.util.deleteFromArray(MLItems[a[l]],n);this.ShowItems(a[l])}}}this.arItemsCollList[s]=t;for(l=0;l<o;l++)this.ShowItems(t[l]);if(this.Search.bShowed){var c,h=window.MLSearchResult.length,p;for(c=0;c<h;c++){p=window.MLSearchResult[c];if(p.id==s){e=this._MergeItemInfo(p,e);window.MLSearchResult[c]=e;window.MLSearchResult[c].collections=t;window.MLSearchResult[c].perm=p.perm;this.Search.DisplayResult(window.MLSearchResult,this.Search.Query);break}}}},_MergeItemInfo:function(e,t){if(typeof e=="object"&&typeof t=="object"){for(var i in t){if(t[i]&&(t[i].length>0||t[i]>0))e[i]=t[i]}}return e},FindItem:function(e,t){if(MLItems[e]&&typeof MLItems[e]=="object"&&MLItems[e].length>0){var i,l=MLItems[e].length;for(i=0;i<l;i++){el=MLItems[e][i];if(el&&el.id==t)return i}}return false},InitMultiaction:function(){var e=this;this.pMultiActCont=BX("ml_multiaction_cnt");if(!this.pMultiActCont)return;this.pCheckAll=BX("ml_action_target");this.arLoadItems={};this.pDelBut=BX("action_delete_button");this.pCheckAll.onclick=function(){var t=!!this.checked,i=e.pCollCont.getElementsByTagName("INPUT"),l,o=i.length;for(l=0;l<o;l++)if(i[l].type=="checkbox")i[l].checked=t;e.EnableMultiAction(t);e.arLoadItems={};if(t)for(l=0,o=e.arCollections.length;l<o;l++)e.arLoadItems[e.arCollections[l].id]=true};this.pDelBut.onclick=function(){if(!e.bMultiActEnabled||!confirm(ML_MESS.MultiDelConfirm))return;var t=e.MultiActGetSelected();e.Request({action:"multi_del",postData:{cols:t.Colls,items:t.Items},handler:function(){e.Refresh({curColl:e.SelectedColId})}})}},AskAllCheckBoxes:function(){var e=this.pCollCont.getElementsByTagName("INPUT");if(this.Search.bShowed)e=[].concat(e,this.Search.GetCheckboxes());for(var t=0,i=e.length;t<i;t++)if(e[t].type=="checkbox"&&e[t].checked)return true;return false},EnableMultiAction:function(e){this.bMultiActEnabled=e;if(e)BX.removeClass(this.pMultiActCont,"multi-dis");else BX.addClass(this.pMultiActCont,"multi-dis")},CheckAllCollChild:function(e,t,i){var l=this.oCollections[e],o,s,n=this.arCollections.length;l.pCheck.checked=t;if(i){this.arMultiSelect={Cols:[e],Items:[],NotLoadedItems:[]}}if(l.childCount>0){for(s=0;s<n;s++){o=this.arCollections[s];if(o.parent==e)this.CheckAllCollChild(o.id,t)}}if(typeof MLItems[e]=="undefined"){if(t){this.arLoadItems[e]=true}else this.arLoadItems[e]=false}else if(typeof MLItems[e]=="object"&&MLItems[e].length>0){var a=l.pChildCont.getElementsByTagName("INPUT"),r=a.length;for(s=0;s<r;s++)if(a[s].type=="checkbox")a[s].checked=t}if(i)this.EnableMultiAction(t||this.AskAllCheckBoxes())},MultiActGetSelected:function(){var e=[],t={},i=this.pCollCont.getElementsByTagName("INPUT"),l,o=i.length,s,n,a,r;for(l=0;l<o;l++){if(i[l].type=="checkbox"&&i[l].checked){s=i[l].value;if(s.indexOf("c_")!=-1){e.push(s.substr(2));continue}n=s.indexOf("|");if(n!=-1){a=s.substr(0,n);r=s.substr(n+1);if(!t[a])t[a]=[];t[a].push(r)}}}if(this.Search.bShowed){this.arChecks=false;var d=this.Search.GetCheckboxes();o=window.MLSearchResult.length;var c,h,p;for(l=0;l<o;l++){c=window.MLSearchResult[l];if(this.Search.checkedChIndex[c.id]){if(c.collections){for(p=0,h=c.collections.length;p<h;p++){a=c.collections[p];if(!t[a])t[a]=[];t[a].push(c.id)}}}}}return{Colls:e,Items:t}},InitContextMenu:function(){var e=this;var t=[{id:"edit",name:ML_MESS.Edit,title:ML_MESS.EditCollection,handler:function(t){e.OpenEditCollDialog({id:t.id.substr("mlccm_".length)})}},{id:"del",name:ML_MESS.Delete,title:ML_MESS.DelCollection,handler:function(t){e.DelCollection(t.id.substr("mlccm_".length))}},{id:"access",name:ML_MESS.Access,title:ML_MESS.AccessTitle,handler:function(e){window.location="/bitrix/admin/fileman_medialib_access.php?col_id="+e.id.substr("mlccm_".length)}},{id:"add_item",name:ML_MESS.AddElement,title:ML_MESS.AddElementTitle,handler:function(t){e.OpenEditItemDialog({parentCol:t.id.substr("mlccm_".length)})}},{id:"add_col",name:ML_MESS.AddCollection,title:ML_MESS.AddCollectionTitle,handler:function(t){e.OpenEditCollDialog({parentCol:t.id.substr("mlccm_".length)})}}];t.push({id:"change_type",name:ML_MESS.ChangeType,title:ML_MESS.ChangeTypeTitle,handler:function(t){e.OpenChangeTypeDialog({id:t.id.substr("mlccm_".length)})}});this.ClearOverlay=new BXOverlay({id:"bx_clear",className:"bx-clear-overlay"});this.oColMenu=new MLContextMenu({id:"coll",Items:t,Overlay:this.ClearOverlay,cmPushed:"ml-col-menu-pushed"})},Refresh:function(e){var t=e?parseInt(e.curColl):0,i=window.location.toString();if(t>0){if(i.indexOf("cur_col=")!=-1)i=i.replace(/(cur_col=)(\d)+/g,"$1"+t);else i+=(i.indexOf("?")==-1?"?":"&")+"cur_col="+t}window.location=i},CheckFileExt:function(e,t){e=e.substr(e.lastIndexOf(".")+1);e=e.toLowerCase();if(!t)t=this.arExt;for(var i=0,l=t.length;i<l;i++)if(t[i]==e)return true;return false},AppendKeywords:function(e,t){if(!e||!t)return;var i=[],l=e.value.split(",").concat(t.split(",")),o,s,n=l.length;for(s=0;s<n;s++){o=BX.util.trim(l[s]);if(o&&!BX.util.in_array(o,i))i.push(o)}e.value=i.join(", ")},InitTypeSelector:function(){this.bTypes=this.Types.length>1;if(this.bTypes){this.pTypeCont=BX("ml_type_cont");this.pTypeCont.style.display="block";this.oTypeSelector=new BXMLTypeSelector({oML:this,Types:this.Types,oCallback:{obj:this,func:this.TypeOnChange}});this.pTypeCont.appendChild(this.oTypeSelector.pWnd);this.oTypeSelector.SetType(this.oConfig.curTypeInd,false);this.curType=this.Types[this.oConfig.curTypeInd]}else{this.curType=this.Types[this.oConfig.curTypeInd]}},TypeOnChange:function(e){if(this.Types[e.typeInd].id!=this.curType.id)window.location="/bitrix/admin/fileman_medialib_admin.php?lang="+this.oConfig.lang+"&type="+this.Types[e.typeInd].id},CheckMLType:function(e){e=parseInt(e);if(!this.bTypes||e==this.curType.id)return true;if((!this.curType||this.curType.code=="image"&&this.curType.system)&&(!e||e==this.curType.id))return true;return false},OpenChangeTypeDialog:function(e){if(!e)e={};if(!this.ChangeTypeDialog)this.CreateChangeTypeDialog();var t=600,i=this.ChangeTypeDialog,l=BX.GetWindowSize(),o=parseInt(l.scrollLeft+l.innerWidth/2-i.width/2),s=parseInt(l.scrollTop+l.innerHeight/2-i.height/2);i.oCol=this.GetCollection(e.id);i.Overlay.Show({zIndex:t-10});i.pWnd.style.zIndex=t;i.pWnd.style.display="block";i.pType.value="none";this._TypeOnChange();jsFloatDiv.Show(this.ChangeTypeDialog.pWnd,o,s);BX.bind(document,"keypress",window.MlChTypeOnKeypress)},CreateChangeTypeDialog:function(e){var t=this,i,l,o={width:360,height:125,pWnd:BX("mlsd_change_type"),pType:BX("mlsd_chtype_type"),pParent:BX("mlsd_chtype_parent"),Overlay:new BXOverlay({id:"bxml_ch_type_overlay"})};o.pType.onchange=function(){t._TypeOnChange()};for(var s=0,n=this.Types.length;s<n;s++){if(this.Types[s].id!=this.curType.id)o.pType.options.add(new Option(this.Types[s].name,s))}this._typeColInd={};this.arTypeCol={};var a=[],r,d=0,s,n=this.arCollections.length;for(s=0;s<n;s++)if(!this._buildTypeCol(this.arCollections[s],s))a.push([this.arCollections[s],s]);while(a.length>0&&d<50){n=a.length;r=[];for(s=0;s<n;s++)if(!this._buildTypeCol(a[s][0],a[s][1]))r.push(a[s]);a=r;d++}BX("mlsd_chtype_save").onclick=function(){if(t.ChangeColType()!==false);t.CloseChangeTypeDialog()};BX("mlsd_chtype_cancel").onclick=function(){t.CloseChangeTypeDialog()};BX("mlsd_chtype_close").onclick=function(){t.CloseChangeTypeDialog()};window.MlChTypeOnKeypress=function(e){if(!e)e=window.event;if(e&&e.keyCode==27)t.CloseChangeTypeDialog()};o.pWnd.style.width=o.width+"px";o.pWnd.style.height=o.height+"px";this.ChangeTypeDialog=o},CloseChangeTypeDialog:function(){this.ChangeTypeDialog.pWnd.style.display="none";jsFloatDiv.Close(this.ChangeTypeDialog.pWnd);this.ChangeTypeDialog.Overlay.Hide();BX.unbind(document,"keypress",window.MlChTypeOnKeypress)},_TypeOnChange:function(){var e=this.ChangeTypeDialog.pParent;if(this.ChangeTypeDialog.pType.value=="none"){e.disabled=true;this._ReqBuildCollSelect(e,[],0,true)}else{e.disabled=false;var t=this.Types[this.ChangeTypeDialog.pType.value];this._ReqBuildCollSelect(e,this.arTypeCol[t.id]||[],0,true)}},_buildTypeCol:function(e,t){if(!e)return false;var i=e.type||this.imageTypeId,l,o;if(!this.arTypeCol[i])this.arTypeCol[i]=[];e.parent=parseInt(e.parent);if(!e.parent){l=0;o=this.arTypeCol[i]}else if(this._typeColInd[e.parent]){l=this._typeColInd[e.parent].level+1;this._typeColInd[e.parent].childCount++;o=this._ReqFindChildCol(this.arTypeCol[i],e.parent)}else return false;if(o&&typeof o=="object")o.push({id:e.id,child:[]});this._typeColInd[e.id]={ind:t,level:l,childCount:0};return true},ChangeColType:function(){var e=this,t=e.ChangeTypeDialog,i=t.pType.value,l=t.pParent.value;if(i!="none"){var o=this._IterGetChildCols(this._ReqFindChildCol(this.arCollectionsTree,t.oCol.id));if(o.length>0&&!confirm(ML_MESS.ChangeTypeChildConf))return false;this.Request({action:"change_col_type",postData:{col:t.oCol.id,type:this.Types[i].id,parent:l,children:o},handler:function(){if(window.bx_req_res===false)alert(ML_MESS.ChangeTypeError);else return e.Refresh()}})}return true},_IterGetChildCols:function(e){var t=[],i,l=e.length;for(i=0;i<l;i++){t.push(e[i].id);if(e[i].child.length>0)t=t.concat(this._IterGetChildCols(e[i].child))}return t}};function BXMLSearch(e){this.oML=e;this.Init()}BXMLSearch.prototype={Init:function(){var e=this;this.bShowed=false;this.pInput=BX("ml_search_input");this.pButton=BX("ml_search_button");this.pResultCont=BX("ml_search_res_cont");this.pResultContDiv=BX("ml_s_res_cnt_div");this.pResultContPar=BX("ml_search_res_cont_par");this.pResultTitle=BX("ml_srch_res_title");this.pResultCheckbox=BX("ml_srch_res_check");this.pResultFlip=BX("ml_srch_res_flip");this.pResultHide=BX("ml_srch_res_hide");this.pButton.onclick=function(){if(e.pInput.value.length>0)e.Search(e.pInput.value)};this.pInput.onkeydown=function(t){if(!t)t=window.event;if(t.keyCode==13&&this.value.length>0)e.Search(this.value)};this.pResultHide.onclick=function(t){e.pResultContPar.style.display="none";e.bShowed=false;return BX.PreventDefault(t)};this.pResultFlip.onclick=function(t){e.OpenResultCont();return BX.PreventDefault(t)};this.pResultCheckbox.onclick=function(t){var i=this.checked,l=e.GetCheckboxes(),o,s=l.length;for(o=0;o<s;o++)l[o].checked=i&&!l[o].disabled;e.oML.EnableMultiAction(i||e.oML.AskAllCheckBoxes());if(!t)t=window.event;if(t.stopPropagation)t.stopPropagation();else t.cancelBubble=true}},GetCheckboxes:function(){this.checkedChIndex={};if(!this.arChecks){this.arChecks=[];var e=this.pResultCont.getElementsByTagName("INPUT"),t,i=e.length;for(t=0;t<i;t++){if(e[t].type=="checkbox"&&e[t].value.indexOf("search_result")!=-1){this.arChecks.push(e[t]);if(e[t].checked)this.checkedChIndex[e[t].value.substr(14)]=true}}}else{for(var t=0,i=this.arChecks.length;t<i;t++)if(this.arChecks[t].checked)this.checkedChIndex[this.arChecks[t].value.substr(14)]=true}return this.arChecks},Search:function(e){var t=this;window.MLSearchResult=false;this.oML.Request({action:"search",postData:{q:e},handler:function(){if(window.MLSearchResult)t.DisplayResult(window.MLSearchResult,e)}})},DisplayResult:function(e,t){this.arChecks=false;this.bOpened=false;this.bShowed=true;this.Query=t;this.pResultContPar.style.display="block";this.OpenResultCont();this.pResultTitle.innerHTML=ML_MESS.SearchResultEx.replace("#SEARCH_QUERY#",BX.util.htmlspecialchars(t));while(this.pResultCont.firstChild)this.pResultCont.removeChild(this.pResultCont.lastChild);var i,l=e.length;if(l>0){for(i=0;i<l;i++)this.oML.DisplayItem({bSearch:true,Item:e[i],pCont:this.pResultCont,bCheck:false,id:"search_result",Access:e[i].perm})}else{this.pResultCont.appendChild(BX.create("DIV",{props:{className:"ml-search-no-result"},text:ML_MESS.NoResult}))}},OpenResultCont:function(){if(!this.bOpened){this.pResultFlip.className="ml-col-icon ml-col-icon-opened";this.pResultContDiv.style.display="block"}else{this.pResultContDiv.style.display="none";this.pResultFlip.className="ml-col-icon ml-col-icon-closed"}this.bOpened=!this.bOpened}};function MLContextMenu(e){this.Items=e.Items;this.oOverlay=e.Overlay;this.zIndex=e.zIndex||600;this.id=e.id||"menu";this.cmPushed=e.cmPushed;this.PreCreate()}MLContextMenu.prototype={PreCreate:function(){this.pref="ML_"+this.id+"_";this.oDiv=document.body.appendChild(BX.create("DIV",{props:{className:"bx-cm",id:this.pref+"_cont"},style:{zIndex:this.zIndex},html:'<table><tr><td class="bxcm-popup"><table id="'+this.pref+'_cont_items"><tr><td></td></tr></table></td></tr></table>'}));this.menu=new PopupMenu(this.pref+"_cont")},Create:function(){this.BuildItems();this.bCreated=true},Show:function(e){if(!this.bCreated)this.Create();this.oDiv.style.width=parseInt(this.oDiv.firstChild.offsetWidth)+"px";this.pElement=e.pElement;var t=jsUtils.GetRealPos(this.pElement),i=this,l=parseInt(this.oDiv.offsetWidth),o=parseInt(this.oDiv.offsetHeight),s=this.oOverlay.Show();if(this.cmPushed)BX.addClass(this.pElement,this.cmPushed);if(e.arHideItems.length>0){var n,a=this.Items.length;for(n=0;n<a;n++){if(typeof this.Items[n]=="object")this.Items[n].pWnd.style.display=e.arHideItems[this.Items[n].id]?"none":BX.browser.IsIE()?"inline":"table-cell"}}s.onclick=function(){i.Close()};window.overlay_keypress=function(e){i.OnKeyPress(e)};BX.bind(window,"keypress",window.overlay_keypress);t.top+=2;t.left+=1;this.menu.PopupShow(t)},Close:function(){this.menu.PopupHide();this.oOverlay.Hide();if(this.cmPushed)BX.removeClass(this.pElement,this.cmPushed);BX.unbind(window,"keypress",window.overlay_keypress)},BuildItems:function(){var e=BX(this.pref+"_cont_items"),t=this.Items.length;_this=this;var i,l,o;for(i=0;i<t;i++){o=this.Items[i];l=e.insertRow(-1).insertCell(-1);if(o=="separator"){l.innerHTML='<div class="popupseparator"></div>'}else{l.innerHTML='<table class="popupitem" id="bx_cm_'+o.id+'"><tr><td class="gutter"><div class="bx-button" id="bx_btn_'+o.id+'" ></div></td><td class="item">'+o.name+"</td></tr></table>";var s=l.firstChild;s.onmouseover=function(e){this.className="popupitem popupitemover"};s.onmouseout=function(e){this.className="popupitem"};s.onclick=function(e){_this.OnClick(this)};o.pWnd=l}}this.oDiv.style.width=e.parentNode.offsetWidth;return true},OnClick:function(e){var t,i=this.Items.length,l=e.id.substring("bx_cm_".length);this.Close();for(t=0;t<i;t++)if(this.Items[t].id==l&&this.Items[t].handler)return this.Items[t].handler(this.pElement)},OnKeyPress:function(e){if(!e)e=window.event;if(e.keyCode==27)this.Close()}};
//# sourceMappingURL=core_admin.map.js